package com.sjb.stock.service.impl;

import com.sjb.stock.domain.InnerMarketDomain;
import com.sjb.stock.pojo.entity.StockBusiness;
import com.sjb.stock.pojo.mapper.StockBusinessMapper;
import com.sjb.stock.pojo.mapper.StockMarketIndexInfoMapper;
import com.sjb.stock.service.StockService;
import com.sjb.stock.utils.DateTimeUtil;
import com.sjb.stock.vo.StockInfoConfig;
import com.sjb.stock.vo.resp.R;
import org.joda.time.DateTime;
import org.joda.time.format.DateTimeFormat;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Date;
import java.util.List;

/**
 * @FileName StockServiceImpl
 * @Description
 * @Author chm
 * @date 2025-10-13
 **/
@Service("StockService")
public class StockServiceImpl implements StockService {
    @Resource
    private StockBusinessMapper stockBusinessMapper;

    @Resource
    private StockMarketIndexInfoMapper stockMarketIndexInfoMapper;

    @Resource
    private StockInfoConfig stockInfoConfig;

    /**
     * 获取国内大盘的实时数据
     * @return com.sjb.stock.vo.resp.R<java.util.List<com.sjb.stock.domain.InnerMarketDomain>>
     */
    @Override
    public R<List<InnerMarketDomain>> innerIndexAll() {
        //1.获取国内A股大盘的id集合
        List<String> inners = stockInfoConfig.getInner();
        //2.获取最近股票交易日期
        Date lastDate = DateTimeUtil.getLastDate4Stock(DateTime.now()).toDate();
        //TODO mock测试数据，后期数据通过第三方接口动态获取实时数据 可删除
        lastDate=DateTime.parse("2022-01-02 09:32:00", DateTimeFormat.forPattern("yyyy-MM-dd HH:mm:ss")).toDate();
        //3.将获取的java Date传入接口
        List<InnerMarketDomain> list= stockMarketIndexInfoMapper.getMarketInfo(inners,lastDate);
        //4.返回查询结果
        return R.ok(list);
    }
}
